package main
import (
	"fmt"
	"strings"
)

func main(){
	//字符串替换
	replace_str1 := strings.Replace("goandjavagogo","go","golang",-1)
	replace_str2 := strings.Replace("goandjavagogo","go","golang",2)	//只替换2处
	fmt.Printf("替换后的字符串为：%s \n",replace_str1)
	fmt.Printf("替换后的字符串为：%s \n",replace_str2)

	//按照指定的字符，进行字符串的切割
	split := strings.Split("php-go-java","-")
	fmt.Println(split);

	//将字符串转换成大写
	to_upper := strings.ToUpper("golang")
	fmt.Println("字符串转换大写：",to_upper)

	//将字符串转换成小写
	to_lower := strings.ToLower("GOLANG")
	fmt.Println("字符串转换小写：",to_lower)

	//字符串左右两边指定字符串去除
	trim := strings.Trim("~       golang        ~","~")
	fmt.Printf("去除字符串两端的空格%s \n",trim)


	//字符串左右两边空格去除
	trim_space := strings.TrimSpace("       go lang        ")
	fmt.Printf("去除字符串两端的空格%s \n",trim_space)

	//去除字符串左边的指定字符串
	trim_left := strings.TrimLeft("~	golang	~","~")
	fmt.Printf("去除左侧的～：%s \n",trim_left)

	//去除字符串右边的指定字符串
	trim_right := strings.TrimRight("~	golang	~","~")
	fmt.Printf("去除右侧的～：%s \n",trim_right)

	//判断字符串是否以指定的字符串开头：
	has_prefix := strings.HasPrefix("Hello World","Hello")
	fmt.Printf("字符串是否以Hello为开头：%t \n",has_prefix)

	//判断字符串是否以指定的字符串结尾：
	has_suffix := strings.HasSuffix("Hello World","World")
	fmt.Printf("字符串是否以World为结尾：%t \n",has_suffix)
}